package com.mallcai.bigdata.ladon.controller.peekdata.form;

import com.mallcai.bigdata.ladon.controller.BaseForm;
import com.mallcai.bigdata.ladon.dpl.entity.peekdata.Model;
import com.mallcai.bigdata.ladon.dpl.entity.peekdata.ModelMeta;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * Created by oneape<oneape15@163.com>
 * Created 2019-05-22 13:43.
 * Modify:
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ModelForm extends BaseForm {
    @NotNull(message = "模型Id不能为空", groups = {IdCheck.class, EditCheck.class, ChangeStatusCheck.class,GetUpgradeColumnCheck.class})
    private Long    modelId; // 模型Id
    @NotNull(message = "请选择数据源", groups = {AddCheck.class, EditCheck.class, GetColumnCheck.class,GetUpgradeColumnCheck.class})
    private Long    datasourceId; // 数据源Id
    @NotNull(message = "数据表不能为空", groups = {AddCheck.class, EditCheck.class, GetColumnCheck.class,GetUpgradeColumnCheck.class})
    private String  tableName;    // 具体表名
    @NotNull(message = "模型名称不能为空", groups = {AddCheck.class, EditCheck.class})
    private String  name;         // 模型名称
    @NotNull(message = "模型状态不能为空", groups = {ChangeStatusCheck.class})
    private Integer status;       // 模型状态 0 - 使用中; 1 - 已停用
    private String  desc;         // 描述

    private List<ModelMeta> fields;  // 表字段列表

    public interface IdCheck {
    }

    public interface AddCheck {
    }

    public interface EditCheck {
    }

    public interface ChangeStatusCheck {
    }

    public interface GetColumnCheck {
    }
    public interface GetUpgradeColumnCheck {
    }

    public Model toEntity() {
        Model m = new Model();
        BeanUtils.copyProperties(this, m);
        m.setId(modelId);
        return m;
    }

}
